'use strict';
// Copyright 2014 Blueant Inc. All Rights Reserved.

/**
 * @fileoverview vip等级
 * @author sundbcn@gmail.com (sun debing)
 */

var moment = require('moment');
var modelUtil = require('../util/modelUtil');
var constantUtil = require('../util/constantUtil');
var mongoConnector = require('../libs/mongodb/mongoConnector');
/* jshint unused:false */
var haveHelpSchema = require('../schemas/haveHelpSchema.js');
var HaveHelp = mongoConnector().model('HaveHelp');

/**
 * 根据role_id获取model
 * @return {[type]} [description]
 */
module.exports.getById = function (role_id, only_id, cb) {
    HaveHelp.findOne({
        role_id: role_id,
        only_id: only_id
    }, function (err, union_group_model) {
        if (!!err) {
            console.error(err);
            return cb();
        }
        cb(null, union_group_model);
    });
};

/**
 * 增加信息
 */
module.exports.createHaveHelp = function (have_info, cb) {
    HaveHelp.create(have_info, cb);
};

/**
 * 查找已帮助信息
 */
module.exports.findUnionHelpList = function (role_id, cb) {
    HaveHelp.find({
        role_id: role_id
    }).exec(cb);
};

/**
 * 按帮助ID列表查找已帮助信息
 */
module.exports.findByOnlyIdList = function (only_id_list, cb) {
    HaveHelp.find({
        only_id: {
            $in: only_id_list
        }
    }).exec(cb);
};

/**
 * 判断是否已帮助过指定队列
 */
module.exports.checkAlreadyHelp = function (role_id, require_role_id, help_type, share_id, cb) {
    HaveHelp.count({
        role_id: role_id,
        require_role_id: require_role_id,
        help_type: help_type,
        share_id: share_id
    }).exec(function (err, num) {
        cb(err, num > 0);
    });
};

/**
 * 查找已帮助信息
 */
module.exports.findUnionOnlyIdHelpList = function (only_id, cb) {
    HaveHelp.find({
        only_id: only_id
    }).exec(cb);
};

/**
 * 删除已帮助信息
 */
module.exports.removeMsg = function (only_id, cb) {
    HaveHelp.remove({
        only_id: only_id
    }, cb);
};

/**
 * 删除已帮助信息列表
 */
module.exports.removeMsgList = function (only_id_list, cb) {
    HaveHelp.remove({
        only_id: {
            $in: only_id_list
        }
    }, cb);
};
